﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenTK;
using System.Windows.Forms;

namespace GenericGameLibrary
{
    class TkFastLoop
    {

        public delegate void LoopCallback(double elapsedTime); //Container variable for function that will be looped continuously

        PreciseTimer _timer = new PreciseTimer();
        GLControl gfxControl;  //sets local OpenTK control variable
        LoopCallback _callback; //stores sent function for future use

        TkFastLoop(LoopCallback callback, GLControl glcontrol)
        {
            gfxControl = glcontrol; //gets the OpenTK control and stores it in a variable
            _callback = callback; //set local _callback to function that is sent in args


            Application.Idle += (sender, e) =>
                {
                    while (gfxControl.IsIdle) //checks to see if its idle
                    {
                        _callback(_timer.GetElapsedTime());  //continuously loops the function that was sent
                    }
                };
        }
    }
}
